package cn.gdrj.est.controller;

import cn.gdrj.est.dto.CommonResult;
import cn.gdrj.est.entity.Users;
import cn.gdrj.est.service.UsersService;
import cn.gdrj.est.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//  @Controller
//  @ResponseBody
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private UsersService usersService;

    // @RequestMapping(value="test1",method={RequestMethod.GET})
    @GetMapping("test1")
    public String test1(){
        return "test ok!";
    }

    @GetMapping("getuserbyid")
    public Users getById(Long id){
        return usersService.findById(id);
    }

    @GetMapping("getuserbyid2")
    public CommonResult<Users> test2(Long id){

        Users users = usersService.findById(id);
        CommonResult<Users> result = new CommonResult<>();
        result.setCode("0");
        result.setMsg("操作成功");
        result.setData(users);
        return result;
    }

    @GetMapping("getuserbyid5")
    public CommonResult<Users> test5(Long id){
        Users users = usersService.findById(id);
        return ResultUtil.success(users);
    }

    @GetMapping("getuserbyid3")
    public CommonResult<Users> test3(Long id){

        CommonResult<Users> result = new CommonResult<>();
        result.setCode("-1");
        result.setMsg("操作失败");
        return result;
    }

    @GetMapping("getuserbyid4")
    public CommonResult<Users> test4(Long id){

        return ResultUtil.fail();
    }

}
